import Vue from 'vue'
import { checkButtonPermission } from '@/utils/auth'

export default {
  inserted: function(el, binding) {
    if (!checkButtonPermission(binding.value)) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  },
  // 绑定值发生改变或者绑定元素所在区域重新渲染，执行update
  update: function(el, binding) {
    if (!checkButtonPermission(binding.value)) {
      // 放在nextTick保证el dom元素挂载完成之后进行remove操作
      Vue.nextTick(() => {
        el.parentNode && el.parentNode.removeChild(el)
      })
    }
  }
}
